package com.kede.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kede.entity.Product;
import com.kede.dao.ProductDao;
import com.kede.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 【请填写作者】
 * @since 2020-04-02
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao, Product> implements ProductService {

    @Autowired
    ProductDao productDao;
    @Override
    public List<Product> getListByMid(long mid) {
        QueryWrapper<Product> wrapper=new QueryWrapper<Product>();
        wrapper.eq("type",mid);
        List<Product> productList = productDao.selectList(wrapper);
        return productList;
    }

    /**
     * 产品更新
     * @param product
     * @return
     */
    @Override
    public boolean updatebp(Product product) {
        QueryWrapper<Product> wrapper = new QueryWrapper<Product>();
        productDao.update(product,wrapper);
        if(productDao.delete(wrapper)>0){
        return true;
    }
        return false;
}

    /**
     * 产品删除
     * @param id
     * @return
     */
    @Override
    public boolean deletByid(long id) {
        QueryWrapper<Product> wrapper = new QueryWrapper<Product>();
        wrapper.eq("id",id);
        if(productDao.delete(wrapper)>0){
            return true;
        }
        return false;
    }

}
